<template>
	<view class="container">

		<uni-section title="食物轮播图展示" sub-title="" type="line">
			<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
				<swiper-item v-for="(item, index) in foodSwiperList" :key="index">
					<view class="swiper-item">
						<image :src="`http://localhost:8090${item.icon}`" mode="widthFix"></image>
					</view>
				</swiper-item>
			</swiper>
		</uni-section>
		<uni-section title="食物类别宫格展示" sub-title="" type="line">
			<uni-grid :column="3">
				<uni-grid-item v-for="(item, index) in foodTypeList" :key="index">
					<view class="food-type-item">
						<view class="food-type-item-image">
							<image :src="`http://localhost:8090${item.icon}`" mode="aspectFill"></image>
						</view>
						<view class="food-type-item-title">
							<text>{{item.typename}}</text>
						</view>
					</view>
				</uni-grid-item>
			</uni-grid>
		</uni-section>
		<uni-section :title="`食物列表展示(${foodList.length})条`" sub-title="" type="line">
			<uni-list>
				<uni-list-item v-for="(item, index) in foodList" :key="index" :title="item.name" note=""
					:thumb="`http://localhost:8090${item.icon}`" :right-text="`¥${item.price}`" clickable
					@click="openFooddetail(item.id)">

				</uni-list-item>
			</uni-list>
		</uni-section>
		<uni-section :title="`食物评论列表展示(${commentList.length})条`" sub-title="" type="line">
			<uni-list>
				<uni-list-item v-for="(item, index) in commentList" :key="index" :title="item.comment" note="" :right-text="item.postdate"></uni-list-item>
			</uni-list>
		</uni-section>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				foodSwiperList: [],
				foodTypeList: [],
				foodList: [],
			commentList:[]
			}
		},
		methods: {
			openFooddetail(foodId) {
				uni.navigateTo({
					url: `/pages/food/fooddetail/fooddetail?foodId=${foodId}`
				})
			}
		},
		onLoad() {
			uni.request({
				url: 'http://localhost:8090/foodapp/foodSwiper/list',
				method: 'POST',
				success: res => {
					this.foodSwiperList = res.data.list;
				}
			});
			uni.request({
				url: 'http://localhost:8090/foodapp/foodType/list',
				method: 'POST',
				success: res => {
					this.foodTypeList = res.data.list;
				}
			});
			uni.request({
				url: 'http://localhost:8090/foodapp/food/list',
				method: 'POST',
				success: res => {
					this.foodList = res.data.list;
				}
			});
		uni.request({
			url: 'http://localhost:8090/foodapp/comment/list',
			method: 'POST',
			success: res => {
				this.commentList = res.data.list;
			}
		});
		}
	}
</script>

<style>
	image {
		width: 100%;
		height: 100%;
	}

	.swiper-item {
		width: 100%;
		height: 100%;
	}

	.food-type-item {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.food-type-item-image {
		width: 60%;
		height: 60%;
	}
</style>
